/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
class Solution {
public:
    ListNode* deleteDuplication(ListNode* pHead) {
        if(pHead == nullptr) return pHead;
        ListNode* dummy = new ListNode (0);  // 虚拟头节点
        dummy->next = pHead;
        ListNode* cur = pHead, *pre = dummy;
        
        while(cur != nullptr && cur->next != nullptr){
            ListNode* nxt = cur->next;
            if(cur->val == nxt->val){
                // 找到下一个第一次出现的节点
                while(nxt != nullptr && cur->val == nxt->val){
                    nxt = nxt->next;
                }
                pre->next = nxt;   // 删除cur
            }
            else
                pre = cur;
            // 更新cur
            cur = nxt;
        }
        return dummy->next;
    }
};